﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using Expect.Core;

namespace Expect.VisualStudio.Extensions.Services
{
    public class ClassMap
    {
        public string ClassName { get; set; }

        public string FullName { get; set; }

        public ProjectItem Item { get; set; }

        public bool IsFixture { get; set; }

        public bool IsActorFixture { get; set; }

        public bool IsSpecification { get; set; }

        public bool IsContainer { get; set; }

        private List<string> _classHints = new List<string>();

        public List<string> ClassHints
        {
            get
            {
                return this._classHints;
            }
            set
            {
                this._classHints = value;
            }
        }

        private List<string> _methodsHints = new List<string>();

        public List<string> MethodsHints
        {
            get
            {
                return this._methodsHints;
            }
            set
            {
                this._methodsHints = value;
            }
        }

        private List<string> _reducedClassHints = null;

        public List<string> ReducedClassHints
        {
            get
            {
                return this._reducedClassHints;
            }
            set
            {
                this._reducedClassHints = value;
            }
        }

        public bool MapsTo(string name)
        {
            return string.Compare(ClassName, name, true) == 0 || this.MapsToReduced(name);
        }

        public bool MapsToReduced(string name)
        {
            if (ReducedClassHints == null || ReducedClassHints.Count == 0) return false;

            return ReducedClassHints.Any(r => string.Compare(r, name, true) == 0);
        }

        public void Reduce(INameProvider np)
        {
            ReducedClassHints = new List<string>();
            foreach (var hint in ClassHints)
            {
                string[] tokens = hint.Split('|');
                FixtureRow row = new FixtureRow(tokens);
                ReducedClassHints.Add(np.ElementName(row.NamesForFluent().ToArray()));
            }
        }
    }
}
